﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

/// <summary>
/// 终端站点所有页面的基类(运行时)
/// </summary>
public class SitePageBaseRun : Shove.Web.UI.ShoveWebPartBasePageRun
{
    #region 将 ViewState 文本保存在 Session 中，要求：一定要将 Session 存放到 SQLServer 中，不要存放到 InProc 或者 AspState.

    private string _pageGuid = null;

    public string PageGUID
    {
        get
        {
            if (_pageGuid == null)
            {
                _pageGuid = this.Request.Form["__ShoveViewState"];
            }

            if (_pageGuid == null)
            {
                _pageGuid = Guid.NewGuid().ToString();
            }

            return _pageGuid;
        }
        set
        {
            _pageGuid = value;
        }
    }

    protected override object LoadPageStateFromPersistenceMedium()
    {
        return Session[this.PageGUID];
    }

    protected override void SavePageStateToPersistenceMedium(object state)
    {
        RegisterHiddenField("__ShoveViewState", this.PageGUID);
        Session[this.PageGUID] = state;
    }

    #endregion

    public Site _Site = null;

    public SitePageBaseRun()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    protected override void OnLoad(EventArgs e)
    {
        // 获取站点
        _Site = new Site()[Shove._Web.Utility.GetUrlWithoutHttp()];

        if (_Site == null)
        {
            // 没有找到域名的话，就假设是系统，转到 /Default.aspx
            this.Response.Redirect("~/Default.aspx", true);

            return;
        }    

        base.OnLoad(e);
    }
}
